home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / df / RCS / df.c,v < prev    next >
Encoding:
Text File  |  1991-08-19  |  7.1 KB  |  343 lines

  1. head     1.5;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.5
  10. date     91.08.19.13.03.36;  author mendel;  state Exp;
  11. branches ;
  12. next     1.4;
  13.  
  14. 1.4
  15. date     89.06.21.08.20.00;  author ouster;  state Exp;
  16. branches ;
  17. next     1.3;
  18.  
  19. 1.3
  20. date     88.09.23.17.50.38;  author ouster;  state Exp;
  21. branches ;
  22. next     1.2;
  23.  
  24. 1.2
  25. date     88.08.07.17.45.10;  author ouster;  state Exp;
  26. branches ;
  27. next     1.1;
  28.  
  29. 1.1
  30. date     88.08.07.17.37.01;  author ouster;  state Exp;
  31. branches ;
  32. next     ;
  33.  
  34.  
  35. desc
  36. @@
  37.  
  38.  
  39. 1.5
  40. log
  41. @Allow for host names upto 10 characters before display get ragged.
  42. /
  43. @
  44. text
  45. @/* 
  46.  * prefix.c --
  47.  *
  48.  *    Program to manipulate the prefix table.
  49.  *
  50.  * Copyright 1988 Regents of the University of California
  51.  * Permission to use, copy, modify, and distribute this
  52.  * software and its documentation for any purpose and without
  53.  * fee is hereby granted, provided that the above copyright
  54.  * notice appear in all copies.  The University of California
  55.  * makes no representations about the suitability of this
  56.  * software for any purpose.  It is provided "as is" without
  57.  * express or implied warranty.
  58.  */
  59.  
  60. #ifndef lint
  61. static char rcsid[] = "$Header: /a/newcmds/df/RCS/df.c,v 1.4 89/06/21 08:20:00 ouster Exp $ SPRITE (Berkeley)";
  62. #endif not lint
  63.  
  64. #include <errno.h>
  65. #include <fs.h>
  66. #include <fsCmd.h>
  67. #include <host.h>
  68. #include <stdio.h>
  69. #include <string.h>
  70. #include <status.h>
  71. #include <sysStats.h>
  72. #include <sys/types.h>
  73. #include <sys/stat.h>
  74.  
  75. /*
  76.  *----------------------------------------------------------------------
  77.  *
  78.  * main --
  79.  *
  80.  *    Main program for "df":  print disk free space info.
  81.  *
  82.  * Results:
  83.  *    None.
  84.  *
  85.  * Side effects:
  86.  *    None.
  87.  *
  88.  *----------------------------------------------------------------------
  89.  */
  90.  
  91. main(argc, argv)
  92.     int argc;
  93.     char *argv[];
  94. {
  95.     register ReturnStatus status = SUCCESS;    /* status of system calls */
  96. #define MAX_PREFIXES 100
  97.     Fs_Prefix prefixes[MAX_PREFIXES];
  98.     struct stat buf;
  99.     int i, numDomains, maxLength;
  100.  
  101.     /*
  102.      * For each argument, stat the argument in order to make sure that
  103.      * there's a prefix table entry loaded for it.  If the file can't
  104.      * be found, then mark the entry so we don't try to print it later.
  105.      */
  106.  
  107.     for (i = 1; i < argc; i++) {
  108.     if (stat(argv[i], &buf) < 0) {
  109.         fprintf(stderr, "%s couldn't find \"%s\": %s.\n", argv[0],
  110.             argv[i], strerror(errno));
  111.     }
  112.     }
  113.  
  114.     /*
  115.      * Collect information for all known domains.
  116.      */
  117.  
  118.     maxLength = 0;
  119.     for (numDomains = 0; ; numDomains++) {
  120.     bzero((char *) &prefixes[numDomains], sizeof(Fs_Prefix));
  121.     status = Sys_Stats(SYS_FS_PREFIX_STATS, numDomains,
  122.         (Address) &prefixes[numDomains]);
  123.     if (status != SUCCESS) {
  124.         break;
  125.     }
  126.     i = strlen(prefixes[numDomains].prefix);
  127.     if (i > maxLength) {
  128.         maxLength = i;
  129.     }
  130.     }
  131.  
  132.     /*
  133.      * If no args were given, then print all domains.  Otherwise just
  134.      * find the ones matching the names given.
  135.      */
  136.  
  137.     if (argc == 1) {
  138.     for (i = numDomains-1; i >= 0; i--) {
  139.         PrintDiskInfo(&prefixes[i], maxLength);
  140.     }
  141.     } else {
  142.     for (i = 1; i < argc; i++) {
  143.         int j;
  144.  
  145.         /*
  146.          * For each of the names given, find the domain that
  147.          * contains the file, by comparing server and domain ids
  148.          * between the file and the prefix table entries.
  149.          */
  150.  
  151.         if (stat(argv[i], &buf) < 0) {
  152.         continue;
  153.         }
  154.         for (j = numDomains-1; j >= 0; j--) {
  155.         if ((prefixes[j].serverID == buf.st_serverID)
  156.             && (prefixes[j].domain == ((int) buf.st_dev))) {
  157.             PrintDiskInfo(&prefixes[j], maxLength);
  158.             break;
  159.         }
  160.         }
  161.     }
  162.     }
  163.     exit(0);
  164. }
  165.  
  166. /*
  167.  *----------------------------------------------------------------------
  168.  *
  169.  * PrintDiskInfo --
  170.  *
  171.  *    Given an Fs_Prefix entry, print disk utilization info for
  172.  *    the prefix.
  173.  *
  174.  * Results:
  175.  *    None.
  176.  *
  177.  * Side effects:
  178.  *    Stuff gets printed on stdout.
  179.  *
  180.  *----------------------------------------------------------------------
  181.  */
  182.  
  183. PrintDiskInfo(prefixPtr, nameSpace)
  184.     register Fs_Prefix *prefixPtr;    /* Information about prefix. */
  185.     int nameSpace;            /* Leave at least this much space
  186.                      * in the "prefix name" column. */
  187. {
  188.     static char serverName[32];
  189.     static int  prevServerID = -1;
  190.     static int  firstTime = 1;
  191.     int        inUse;
  192.     int        free;
  193.     int        avail;
  194.     Host_Entry  *host;
  195.  
  196.     if (firstTime) {
  197.     printf("%-*s  %-10s %10s %10s %10s %9s\n", nameSpace,
  198.         "Prefix", "Server", "KBytes", "Used", "Avail", "% Used");
  199.     firstTime = 0;
  200.     }
  201.     printf("%-*s", nameSpace, prefixPtr->prefix);
  202.  
  203.     if (prefixPtr->serverID > 0) {
  204.  
  205.     /*
  206.      * If the server ID is the same as the previous entry's ID, then
  207.      * we can reuse serverName and save a call to Host_ByID.
  208.      */
  209.     if (prefixPtr->serverID == prevServerID) {
  210.         printf("  %-10s", serverName);
  211.     } else {
  212.         host = Host_ByID(prefixPtr->serverID);
  213.         if (host != (Host_Entry *)NULL) {
  214.         register int charCnt;
  215.         for (charCnt = 0 ; charCnt < sizeof(serverName) ; charCnt++) {
  216.             if (host->name[charCnt] == '.' ||
  217.             host->name[charCnt] == '\0') {
  218.             serverName[charCnt] = '\0';
  219.             break;
  220.             } else {
  221.             serverName[charCnt] = host->name[charCnt];
  222.             }
  223.         }
  224.         serverName[sizeof(serverName)-1] = '\0';
  225.         printf("  %-10s", serverName);
  226.         prevServerID = prefixPtr->serverID;
  227.         } else {
  228.         printf(" (%d)", prefixPtr->serverID);
  229.         }
  230.     }
  231.     } else {
  232.     printf("  %-10s", "(none)");
  233.     }
  234.     if (prefixPtr->domainInfo.maxKbytes <= 0) {
  235.     printf("\n");
  236.     return;
  237.     }
  238.  
  239.     free = prefixPtr->domainInfo.freeKbytes - 
  240.                 (0.1 * prefixPtr->domainInfo.maxKbytes);
  241.     avail = 0.9 * prefixPtr->domainInfo.maxKbytes;
  242.     inUse = avail - free;
  243.  
  244.     printf(" %10d %10d %10d %7d%%\n", 
  245.     prefixPtr->domainInfo.maxKbytes, inUse,    free >= 0 ? free : 0,
  246.     (int) (100.0 * (inUse / (float) avail)));
  247. }
  248. @
  249.  
  250.  
  251. 1.4
  252. log
  253. @Allow arbitrary-length prefix names, and compute column width
  254. dynamically.
  255. @
  256. text
  257. @d17 1
  258. a17 1
  259. static char rcsid[] = "$Header: /a/newcmds/df/RCS/df.c,v 1.3 88/09/23 17:50:38 ouster Exp Locker: ouster $ SPRITE (Berkeley)";
  260. d153 1
  261. a153 1
  262.     printf("%-*s  %-8s %10s %10s %10s %9s\n", nameSpace,
  263. d166 1
  264. a166 1
  265.         printf("  %-8s", serverName);
  266. d181 1
  267. a181 1
  268.         printf("  %-8s", serverName);
  269. d188 1
  270. a188 1
  271.     printf("  %-8s", "(none)");
  272. @
  273.  
  274.  
  275. 1.3
  276. log
  277. @Bad termination condition for loop.
  278. @
  279. text
  280. @d17 1
  281. a17 1
  282. static char rcsid[] = "$Header: df.c,v 1.2 88/08/07 17:45:10 ouster Exp $ SPRITE (Berkeley)";
  283. d55 1
  284. a55 1
  285.     int i, numDomains;
  286. d74 1
  287. d82 4
  288. d95 1
  289. a95 1
  290.         PrintDiskInfo(&prefixes[i]);
  291. d113 1
  292. a113 1
  293.             PrintDiskInfo(&prefixes[j]);
  294. d139 4
  295. a142 2
  296. PrintDiskInfo(prefixPtr)
  297.     register Fs_Prefix *prefixPtr;
  298. d153 1
  299. a153 1
  300.     printf("%-12s %-8s %10s %10s %10s %9s\n",
  301. d157 1
  302. a157 1
  303.     printf("%-12s", prefixPtr->prefix);
  304. d166 1
  305. a166 1
  306.         printf(" %-8s", serverName);
  307. d181 1
  308. a181 1
  309.         printf(" %-8s", serverName);
  310. d188 1
  311. a188 1
  312.     printf(" %-8s", "(none)");
  313. @
  314.  
  315.  
  316. 1.2
  317. log
  318. @Changed "Capacity" to "% Used".
  319. @
  320. text
  321. @d17 1
  322. a17 1
  323. static char rcsid[] = "$Header: df.c,v 1.1 88/08/07 17:37:01 ouster Exp $ SPRITE (Berkeley)";
  324. d105 1
  325. a105 1
  326.         for (j = numDomains-1; j > 0; j--) {
  327. @
  328.  
  329.  
  330. 1.1
  331. log
  332. @Initial revision
  333. @
  334. text
  335. @d17 1
  336. a17 1
  337. static char rcsid[] = "$Header: prefix.c,v 1.1 88/08/07 14:43:03 ouster Exp $ SPRITE (Berkeley)";
  338. d146 2
  339. a147 2
  340.     printf("%-12s %-8s %10s %10s %10s %10s\n",
  341.         "Prefix", "Server", "KBytes", "Used", "Avail", "Capacity");
  342. @
  343.